unit Monitoramento;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, DB, DBTables;

type
  TFMonitoramento = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Bevel1: TBevel;
    Bevel2: TBevel;
    Bevel3: TBevel;
    Bevel4: TBevel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Bevel5: TBevel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    QryL: TQuery;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FMonitoramento: TFMonitoramento;

implementation

uses UGestao, UGeral;

{$R *.dfm}

procedure TFMonitoramento.FormCreate(Sender: TObject);
const
  ctPesquisa = 'select count(*) from pedidovenda %s';
var
  i : integer;

  function condicao(posicao : integer):String;
  begin

    case posicao of
      0:result := 'where (ped_situacao = 1) and (excluido <> ''S'' or excluido is null) and (codigoempresa = '+ intToStr(codigoempresa) +')';
      1:result := 'where (ped_situacao = 0) and (excluido <> ''S'' or excluido is null) and (codigoempresa = '+ intToStr(codigoempresa) +')';
      2:result := 'where (ped_situacao = 2) and (excluido <> ''S'' or excluido is null) and (codigoempresa = '+ intToStr(codigoempresa) +')';
      3:result := 'where (excluido = ''S'') and (codigoempresa = '+ intToStr(codigoempresa) +')';
      4:result := 'where (codigoempresa = '+ intToStr(codigoempresa) +')';
    end;

  end;

begin

  DMMySQL.AbrindoConexaoOnLine;

  for i := 0 to 4 do
  begin


    Qry.Close;
    Qry.SQL.Clear;
    Qry.SQl.Add(Format(ctPesquisa, [condicao(i)]));
    Qry.Open;

    TLabel(FindComponent('Label' + intToStr(7 + i))).Caption := IntToStr(Qry.Fields[0].AsInteger);

  end;

  DMMySQL.FechandoConexaoOnLine;

  for i := 0 to 4 do
  begin


    QryL.Close;
    QryL.SQL.Clear;
    QryL.SQl.Add(Format(ctPesquisa, [condicao(i)]));
    QryL.Open;

    TLabel(FindComponent('Label' + intToStr(12 + i))).Caption := IntToStr(QryL.Fields[0].AsInteger);

  end;

end;

end.
